package com.util.cdb.controller;

import com.util.cdb.bean.Result;
import com.util.cdb.bean.vo.QueryBySqlVO;
import com.util.cdb.bean.vo.QueryOperationPageVO;
import com.util.cdb.bean.vo.QueryOperationVO;
import com.util.cdb.service.OperationService;
import com.util.cdb.service.QueryListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @description: 查询结果返回List
 * @author: fengfazheng
 * @create: 2021-12-26 21:49
 **/
@RestController
@RequestMapping("/queryList")
@Api(value = "/queryList", tags = "查询结果返回List")
public class QueryListController  {
    @Autowired
    private QueryListService queryListService;
    @Autowired
    private OperationService operationService;

    @PostMapping("/queryListByOperation")
    @ApiOperation(value = "通过操作查询List", httpMethod = "POST", notes = "通过操作查询List")
    public Result<List<String>> queryListByOperation(@RequestBody QueryOperationVO queryOperationVO) throws SQLException {
        return Result.resultOk(operationService.queryListByOperation(queryOperationVO));
    }

    @PostMapping("/queryListMapByOperation")
    @ApiOperation(value = "通过操作查询分页表数据", httpMethod = "POST", notes = "通过操作查询分页表数据")
    public Result<List<String>> queryListMapByOperation(@RequestBody QueryOperationPageVO queryOperationPageVO) throws SQLException {
        return Result.resultOk(operationService.queryListMapByOperation(queryOperationPageVO));
    }

    @PostMapping("/queryListMap")
    @ApiOperation(value = "通过SQL查询数据", httpMethod = "POST", notes = "通过操作查询分页表数据")
    public Result<List<Map<String, Object>>> queryListMap(@RequestBody QueryBySqlVO queryBySqlVO) throws SQLException {
        return Result.resultOk(queryListService.queryListMapBySql(queryBySqlVO));
    }
}
